import type { formListType, selectOptionsType } from '@/components/Find/index.vue'
import service from '@/utils/request'
import { ElMessage } from 'element-plus'
import { computed } from 'vue'
import { i18n, Jzhcn } from '@/i18n/index'
interface DataType {
  list: []
  total: number
  pageNum: number
  pageSize: number
  totalDays?: number
  totalOrders?: number
  totalNum?: number
}

export interface TableListType {
  Data: DataType
  dataList: []
  srcList: string[]
}
// 获取表格数据
const TableList = async (formList: any, getTableList: any, pageNum: any, pageSize: any) => {
  return new Promise(async (resolve, reject) => {
    let srcList: string[] = []
    let Data: any = []
    const line = formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '生产线')
      ?.selectValue as string
    const brand = formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '品牌')
      ?.selectValue as string
    const customStyle = formList.value.find(
      (item: any) =>
        Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入货号' || item.inputPlaceholder === '请输入工厂货号'
    )?.inputValue as string
    const dutyDept = formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商')
      ?.selectValue as string
    const lotNo =
      (formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入指令'
      )?.inputValue as string) || ''
    const type = formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '采集类型')
      ?.selectValue as string
    const workName = formList.value.find(
      (item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '生产员工'
    )?.selectValue as string
    const seasonType = formList.value.find(
      (item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '季节'
    )?.selectValue as string
    const sampleType = formList.value.find(
      (item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '样品类型'
    )?.selectValue as string
    const deliveryEndTime = formList.value.find(
      (item: any) =>
        (item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '客户交期') || item.dateLabel === '指令交期'
    )?.dateValue?.[1]
    const deliveryStartTime = formList.value.find(
      (item: any) =>
        (item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '客户交期') || item.dateLabel === '指令交期'
    )?.dateValue?.[0]
    const completeEndTime = formList.value.find(
      (item: any) =>
        (item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '完成日期') || item.dateLabel === '出货日期'
    )?.dateValue?.[1]
    const completeStartTime = formList.value.find(
      (item: any) =>
        (item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '完成日期') || item.dateLabel === '出货日期'
    )?.dateValue?.[0]
    const beginStartTime = formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '开始日期'
    )?.dateValue[0]
    const beginEndTime = formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '开始日期'
    )?.dateValue[1]

    const orderStartTime = formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '下单日期'
    )?.dateValue?.[0]
    const orderEndTime = formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '下单日期'
    )?.dateValue?.[1]
    const startSysDate = formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '建档日期'
    )?.dateValue?.[0]
    const endSysDate = formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '建档日期'
    )?.dateValue?.[1]
    const closeStartTime = formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '出货日期'
    )?.dateValue?.[0]
    const closeEndTime = formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '出货日期'
    )?.dateValue?.[1]
    const slipNo =
      (formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入补单号'
      )?.inputValue as string) || ''
    const endslipDate = formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '补料日期'
    )?.dateValue?.[1]
    const startslipDate = formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '补料日期'
    )?.dateValue?.[0]
    const style =
      (formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入型体'
      )?.inputValue as string) || ''
    const process = formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '工艺')
      ?.selectValue as string
    const vendor = formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商')
      ?.selectValue as string

    // console.log(closeEndTime);

    // 多选框数据
    const check = () => {
      const Completed = formList.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '已完成') as formListType
      const incomplete = formList.value.find(
        (item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '未完成'
      ) as formListType
      if (!Completed || !incomplete) return
      if (Completed.checked && incomplete.checked) {
        return '0'
      } else if (Completed.checked) {
        return '1'
      } else if (incomplete.checked) {
        return '2'
      } else {
        ElMessage('必须至少选择一项')
        Completed.checked = true
        incomplete.checked = true
        return '0'
      }
    }
    // 未审核已审核
    const cfmFlag = () => {
      const Unaudited = formList.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '未审核') as formListType
      const Audited = formList.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '已审核') as formListType
      if (!Unaudited || !Audited) return
      if (Unaudited.checked && Audited.checked) {
        return ''
      } else if (Unaudited.checked) {
        return 'N'
      } else if (Audited.checked) {
        return 'Y'
      } else {
        ElMessage('必须至少选择一项')
        Unaudited.checked = true
        Audited.checked = true
        return ''
      }
    }
    // console.log(slipNo);

    Data = await getTableList({
      closeStartTime, //	出货日期 开始
      closeEndTime, //	出货日期 结束
      orderStartTime, //	下单日期 开始
      orderEndTime, //	下单日期 结束
      completeStartTime, //	完成日期 开始
      completeEndTime, //	完成日期 结束
      deliveryStartTime, //	客户交期 开始
      deliveryEndTime, //	客户交期 结束
      startSysDate, //  建档日期 开始
      endSysDate, //  建档日期 结束
      startslipDate, //  补料日期 开始
      endslipDate, //  补料日期 结束
      customStyle, //	工厂货号
      brand, //	品牌
      dutyDept, //	厂商
      lotNo, //	指令号
      type, //	采集类型
      workName, //	生产员工
      sampleType, //  样品类型
      seasonType, //  季节
      slipNo, //  补料单号
      style, //  型体
      process, //  工艺
      vendor, //  厂商
      pageNum, //	当前页
      pageSize, //	每页数量
      check: check(), //	完成情况  0：全部，1 已完成 2 未完成
      cfmFlag: cfmFlag() //  审核状态  Y 已审核 N 未审核
    })

    let dataList: any = Data.list.map((item: any) => {
      item.seqNo = parseFloat(item.seqNo).toFixed(2)
      item.orderQty = parseFloat(item.orderQty).toFixed(2)
      item.prodDays = parseFloat(item.prodDays).toFixed(2)
      item.prodQty = parseFloat(item.prodQty).toFixed(2)
      item.prodTime = item.prodTime?.slice(0, 10)
      item.deliveryDate = item.deliveryDate?.slice(0, 10)
      return item
    })
    // console.log(Data);
    srcList = dataList.map((item: any) => {
      return item.photoPath
    })

    resolve({ Data, dataList, srcList })
  })
}

const selectList = async (formList: any, getSelectList: any) => {
  return new Promise(async (resolve, reject) => {
    let {
      brands,
      works,
      duty,
      types,
      seasons,
      samples,
      styles,
      categories,
      process,
      prodUserName,
      dutyDeptName,
      blFlag,
      remark,
      orderType,
      sysUser,
      materialType,
      vendorName,
      classifies,
      molds,
      dutyRek,
      dutyUsers,
      warehouseNos,
      areaTypes,
      lasts
    } = await getSelectList()
    let last = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '楦头'
    ) as formListType
    let brand = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '品牌'
    ) as formListType
    let work = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '生产员工'
    ) as formListType
    let type = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '采集类型'
    ) as formListType
    let sample = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '样品类型'
    ) as formListType
    let dut = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商'
    ) as formListType
    //季度: await selectList(formList, () => service.get<any, any>(`/prod/getPcProdDynamicCondition`))
    let season = formList.value.find(
      (item: any) =>
        (item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '季度') || item.selectP === '季节'
    ) as formListType
    let sty = formList.value.find(
      (item: any) =>
        (item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '货号') || item.selectP === '型体'
    ) as formListType
    let category = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '大类'
    ) as formListType
    let processes = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '工艺'
    ) as formListType
    // await selectList(formList, () => service.get('/pcOrder/getPcOrderDataRsjCondition'))
    let prodUserNames = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '采集员'
    ) as formListType
    let dutyDeptNames = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '补料部门'
    ) as formListType
    let blFlags = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '补料类型'
    ) as formListType
    // 变更原因： await selectList(formList, () => service.get('/change/getConditionBox'))
    let remarks = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '变更原因'
    ) as formListType
    let orderTypes = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '订购类型'
    ) as formListType
    let sysUsers = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '采购员'
    ) as formListType
    let materialTypes = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '材料类型'
    ) as formListType
    // 厂商代码 厂商名称： await selectList(formList, () => service.get('/MaterialOrder/getOrderCondition'))
    let vendorNames = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称'
    ) as formListType
    let bigClassify = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '大类名称 大类代码'
    ) as formListType
    let midClassify = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '中类名称 中类代码'
    ) as formListType
    let smallClassify = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '小类名称 小类代码'
    ) as formListType
    let mold = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '底模号'
    ) as formListType
    // 责任人 await selectList(formList3, () => service.get('/back/duty/getDutyCondition'))
    let dutyUser = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '责任人'
    ) as formListType
    // 责任原因 await selectList(formList3, () => service.get('/back/duty/getDutyCondition'))
    let dutyRe = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '责任原因'
    ) as formListType
    let warehouseNo = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '分仓库别'
    ) as formListType
    let areaType = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '区位'
    ) as formListType

    // let vendorNames = formList.value.find((item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称') as formListType
    // let category = formList.value.find((item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '大类') as formListType
    // 先将所有的数组清空
    formList.value.forEach((item: any) => {
      if (item.type === 'select') {
        item.selectOptions = []
      }
    })
    // 插入楦头
    if (lasts && last) {
      ;(lasts as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        last.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入品牌
    if (brands && brand) {
      ;(brands as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        brand.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入生产员工
    if (works && work) {
      ;(works as string[]).forEach((item: string, index: any) => {
        if (item === null || item === '') return
        work.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入厂商
    if (duty && dut) {
      ;(duty as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        dut.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入采集类型
    if (types && type) {
      ;(types as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        type.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入季节
    if (seasons && season) {
      ;(seasons as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        season.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入样品类型
    if (samples && sample) {
      ;(samples as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        sample.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入货号
    if (styles && sty) {
      ;(styles as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        sty.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入大类
    if (categories && category) {
      ;(categories as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        category.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入工艺
    if (processes && process) {
      ;(process as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        processes.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入采集员
    if (prodUserName && prodUserNames) {
      ;(prodUserName as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        prodUserNames.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入补料部门
    if (dutyDeptName && dutyDeptNames) {
      ;(dutyDeptName as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        dutyDeptNames.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入补料类型
    if (blFlag && blFlags) {
      ;(blFlag as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        blFlags.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入变更原因
    if (remark && remarks) {
      ;(remark as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        remarks.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入订购类型
    if (orderType && orderTypes) {
      ;(orderType as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        orderTypes.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入采购员
    if (sysUser && sysUsers) {
      ;(sysUser as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        sysUsers.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入材料类型
    if (materialType && materialTypes) {
      ;(materialType as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        materialTypes.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入厂商代码 厂商名称
    if (vendorName && vendorNames) {
      ;(vendorName as string[]).forEach((item: any, index) => {
        if (item === null || item === '') return
        vendorNames.selectOptions?.push({
          optionKey: index,
          optionValue: `${item.vendorNo} ${item.vendorAbbr}`,
          optionLabel: `${item.vendorNo} ${item.vendorAbbr}`
        })
      })
    }
    // 插入大类名称 大类代码
    if (classifies && bigClassify && midClassify) {
      if (midClassify.selectValue !== '' && bigClassify.selectValue !== '') {
        console.log(3)
        ;(classifies as string[]).forEach((item: any, index) => {
          if (item === null || item === '') return
          smallClassify.selectOptions?.push({
            optionKey: `${item.levelCode}`,
            optionValue: `${item.typeName} ${item.levelCode} ${item.typeNo}`,
            optionLabel: `${item.typeName} ${item.typeNo}`
          })
        })
      } else if (bigClassify.selectValue !== '') {
        console.log(2)
        ;(classifies as string[]).forEach((item: any, index) => {
          if (item === null || item === '') return
          midClassify.selectOptions?.push({
            optionKey: `${item.levelCode}`,
            optionValue: `${item.typeName} ${item.levelCode} ${item.typeNo}`,
            optionLabel: `${item.typeName} ${item.typeNo}`
          })
        })
      } else {
        console.log(1)
        ;(classifies as string[]).forEach((item: any, index) => {
          if (item === null || item === '') return
          bigClassify.selectOptions?.push({
            optionKey: `${item.levelCode}`,
            optionValue: `${item.typeName} ${item.levelCode} ${item.typeNo}`,
            optionLabel: `${item.typeName} ${item.typeNo}`
          })
        })
      }
    }
    // 插入底模
    if (molds && mold) {
      ;(molds as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        mold.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入责任人
    if (dutyUsers && dutyUser) {
      ;(dutyUsers as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        dutyUser.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入责任原因
    if (dutyRek && dutyRe) {
      ;(dutyRek as string[]).forEach((item: string, index) => {
        if (item === null || item === '') return
        dutyRe.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入分仓库别
    if (warehouseNo && warehouseNos) {
      ;(warehouseNos as string[]).forEach((item: any, index: any) => {
        if (item === null || item === '') return
        warehouseNo.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入区位
    if (areaTypes && areaType) {
      ;(areaTypes as string[]).forEach((item: any, index: any) => {
        if (item === null || item === '') return
        areaType.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // console.log(type);
    resolve('')
  })
}

// 后端数据是数组
const selectSomeList = async (formList: any, getSelectList: any) => {
  return new Promise(async (resolve, reject) => {
    let res = await getSelectList()
    // 材料类型: await selectSomeList(formList, () => service.get('/back/getMtlType3'))
    let mtls = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '材料类型'
    ) as formListType
    let vendor = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称'
    ) as formListType
    let documentMaker = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '制单员'
    ) as formListType
    let sewingMachines = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '针车组别'
    ) as formListType
    let line = formList.value.find(
      (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '生产线'
    ) as formListType
    // 插入生产线
    if (line && res) {
      res.forEach((item: any, index: any) => {
        if (item === null) return
        line.selectOptions?.push({
          optionKey: index,
          optionValue: `${item}`,
          optionLabel: `${item}`
        })
      })
    }
    // 插入材料类型
    if (mtls && res) {
      res.forEach((item: any, index: any) => {
        if (item === null) return
        mtls.selectOptions?.push({
          optionKey: index,
          optionValue: `${item.typeNo}`,
          optionLabel: `${item.typeNo} ${item.typeName}`
        })
      })
    }
    // 插入厂商代码 厂商名称
    if (vendor && res) {
      res.forEach((item: any, index: any) => {
        if (item === null) return
        vendor.selectOptions?.push({
          optionKey: index,
          optionValue: `${item.vendorNo} ${item.vendorName}`,
          optionLabel: `${item.vendorNo} ${item.vendorName}`
        })
      })
    }
    // 插入制单员
    if (documentMaker && res) {
      res.forEach((item: any, index: any) => {
        if (item === null) return
        documentMaker.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // 插入针车组别
    if (sewingMachines && res) {
      res.forEach((item: any, index: any) => {
        if (item === null) return
        sewingMachines.selectOptions?.push({
          optionKey: index,
          optionValue: item,
          optionLabel: item
        })
      })
    }
    // // 插入费用类型
    // // {
    // // "type_name": "材料补单费用",
    // // "TYPE_NO": "A01"
    // // },
    // if (expenseType && res[0].type_name) {
    //   console.log(res);
    //   res.forEach((item: any, index: any) => {
    //     if (item === null && !item.type_name && !item.TYPE_NO) return
    //     expenseType.selectOptions?.push({
    //       optionKey: index,
    //       optionValue: `${item.type_name} ${item.TYPE_NO}`,
    //       optionLabel: `${item.type_name}`
    //     })
    //   })
    // }
    resolve('')
  })
}

// 开发部-荣阳开发-采集的几个页面
// 1 -板房 、2 -备料 、3  -裁断 、4  -电雕 、5 -印刷 、6 -无缝 、7 -高频 、8 -配套完成 、9 -针车派工 、10 -针车完成 、11 -成型投料 、12 -成型完成 、13 -出货完成、14 -大底完成、15 -成型入库
const AcquisitionModel = async (type = 1, formList: any) => {
  let user = formList.value.find(
    (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '采集员'
  ) as formListType
  const res = (await service.get(`/pack/getProdUser?choose=${type}`)) as any
  if (res && user) {
    user.selectOptions = []
    ;(res.prodName as string[]).forEach((item: any, index: any) => {
      if (item === null || item === '') return
      user.selectOptions?.push({
        optionKey: index,
        optionValue: item,
        optionLabel: item
      })
    })
  }
}

export { TableList, selectList, selectSomeList, AcquisitionModel }

// 使用说明
// const formList = ...
// const currentPage = ref(1)
// const pageSize = ref(20)
// const total = ref(0)
// const tableData = ref([])
// const imgList = ref<string[]>([])
// const getTableList = async () => {
//   let { Data, dataList, srcList } = await TableList(formList, Api.getTableList, currentPage.value, pageSize.value) as TableListType
//   tableData.value = dataList
//   total.value = Data.total
//   imgList.value = srcList
// }
// onMounted(async () => {
//   getTableList()
// })

// 获取下拉列表
// const getSelectList = async () => {
//   await selectList(formList, Api.getSelectList)
// }
